﻿using System;

class WeAllLoveBits
{
    static void Main()
    {
        //Telerik Academy Exam 1 @ 6 Dec 2011 Morning

        int number = int.Parse(Console.ReadLine());

        uint[] result = new uint[number];

        for (int i = 0; i < number; i++)
        {
            uint P = uint.Parse(Console.ReadLine());

            //int Pnew = 0;                     // решение за разгадаване без втория ред за масива result (line 11)
            //while (P > 0)
            //{
            //    Pnew <<= 1;
            //    if ((P & 1) == 1)
            //    {
            //        Pnew |= 1;
            //    }
            //    P >>= 1;
            //}
            //Console.WriteLine(Pnew);      // до тук
            

            //uint invertedP = ~P;  // няма нужда от инверсия, защото             
            //pNew = (P ^ invertedP) & reversedP
            // Since (P ^ invertedP) always is 11111..1111, and 1111.11 & number = number
            // 110011 XOR 001100 = 111111, and 111111 AND 110011 = 110011
            // pNew = reversedP
            
            int bitLength = 32; // The binary length of the number is 32 bits initially            
            while ((P >> (bitLength - 1) & 1) == 0)     // this is the exact length of the binary digit
            {
                bitLength--;
            }

            for (int j = 0; j < bitLength; j++)
            {
                result[i] = (result[i] << 1) | ((P >> j) & 1);  //taking each bit from number P (from right to left) and 
                                                                //put it into Pnew (from left to right)
            }
        }
        for (int i = 0; i < number; i++)        // print the final result
        {
            Console.WriteLine(result[i]);
        }

       
    }
}

